package com.jianggy.observer.listener;

import java.util.ArrayList;
import java.util.List;

public class EventSource {
	private List<ClickListener> listeners = new ArrayList<ClickListener>();
	
	
	/**
	 * add new Listener
	 * @param listener
	 */
	public void addListener(ClickListener listener) {
		listeners.add(listener);
	}
	
	/**
	 * delete a listener
	 * @param listener
	 */
	public void removeListener(ClickListener listener) {
		listeners.remove(listener);
	}
	
	
	public void notifyListeners(CustomEvent event) {
		for (ClickListener clickListener : listeners) {
				clickListener.onClick(event);
		}
	}
	
	
	/**
	 * Simulate user's single click action
	 */
	public void singleClick() {
		CustomEvent eventObject = new CustomEvent(this);
		eventObject.setClick(1);
		notifyListeners(eventObject);
	}
	
	public void doubleClick() {
		CustomEvent eventObject = new CustomEvent(this);
		eventObject.setClick(2);
		notifyListeners(eventObject);
	}
}
